package com.mvvm.start.main.mvvm.v.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mvvm.start.main.R
import com.mvvm.start.main.bean.result.MarketResult
import com.mvvm.start.main.bean.result.Repo


/**
 * @author lmy
 * @功能: 市场脚本Adapter
 * @Creat 1/5/21 9:40 AM
 * @Compony 465008238@qq.com
 */
class MarketPagingListAdapter :
    PagingDataAdapter<MarketResult.Record, MarketPagingListAdapter.ViewHolder>(COMPARATOR) {
    companion object {
        private val COMPARATOR = object : DiffUtil.ItemCallback<MarketResult.Record>() {
            override fun areItemsTheSame(
                oldItem: MarketResult.Record,
                newItem: MarketResult.Record
            ): Boolean {
                return oldItem.id == newItem.id
            }

            override fun areContentsTheSame(
                oldItem: MarketResult.Record,
                newItem: MarketResult.Record
            ): Boolean {
                return oldItem == newItem
            }
        }
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val tvAppName: TextView = itemView.findViewById(R.id.tv_app_name)
        val tvActionNumber: TextView = itemView.findViewById(R.id.tv_action_number)
        val tvIntegral: TextView = itemView.findViewById(R.id.tv_integral)
        val tvDownSize: TextView = itemView.findViewById(R.id.tv_down_size)
        val tvCommentSize: TextView = itemView.findViewById(R.id.tv_comment_size)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.market_list_item, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val marketResult = getItem(position)
        if (marketResult != null) {
            holder.tvAppName.text = marketResult.name
            holder.tvActionNumber.text = "包含了${marketResult.actionNumber}个动作"
            holder.tvIntegral.text = "${marketResult.integral}积分"
            holder.tvDownSize.text = "${marketResult.downSize}下载"
            holder.tvCommentSize.text = "${marketResult.integral}评论"
        }
    }
}